<template>
  <view class="login">
    <view style="width: 100%;">
      <image src="../../static/image/logo.jpg" class="logo" mode=""></image>
      <view class="p1">海南溪棠酒店</view>
      <view class="btn1-box" @click="wechatLogin">
        登录
        <!-- <button class="btn1" type="default" open-type="getPhoneNumber"
          @getphonenumber="getPhoneNumber"></button> -->
      </view>
    </view>
    <!-- ---{{code}} -->
    <!-- <view class="privacy-box">
      <checkbox value="checkEd">隐私政策</checkbox>
    </view> -->
  </view>
</template>

<script>
  import {
    loginfunc
  } from '@/common/fa.mixin.js';
  export default {

    data() {
      return {
        loginCode: '',
        mobileCode: '',
        de:'',
        checkEd:false,
        code:''
      };
    },
    onLoad() {
      
    },
    methods: {
      wechatLogin (){
        uni.showLoading()
        const that = this
        uni.login({
          success(res1) {
            that.code = res1.code
            console.log('rrr', res1)
            if (res1.code) {
              that.$api.wechatLoginApi({logincode: res1.code}).then(res => {
                if (!res.code) return that.$u.toast(res.msg);
                that.$u.vuex('vuex_token', res.data.token);
                uni.showToast({
                  title: res.msg,
                  icon: 'none'
                });
                setTimeout(()=>{
                  uni.reLaunch({
                    url:'/pages/index/index'
                  })
                }, 800)
              })
              uni.hideLoading()
            } else {
              uni.hideLoading()
              console.log('失败！' + res.msg)
            }
          }
        })
              
        
      },
      // e
      getPhoneNumber(e) {
        // uni.showLoading()
        const that = this
        console.log(e)
        that.de = JSON.stringify(e.detail)
        if (!e.detail.code) {
          // uni.hideLoading()
          return uni.showToast({
            title: '请先同意获取手机号权限',
            icon: 'none'
          });
        }
        uni.login({
          success(res1) {
            if (res1.code) {
              that.$api.wechatMobileLoginApi({logincode: res1.code, code: e.detail.code}).then(res => {
                if (!res.code) return this.$u.toast(res.msg);
                that.$u.vuex('vuex_token', res.data.token);
                uni.showToast({
                  title: res.msg,
                  icon: 'none'
                });
                setTimeout(()=>{
                  uni.reLaunch({
                    url:'/pages/index/index'
                  })
                }, 800)
              })
            } else {
              console.log('失败！' + res.msg)
            }
          }
        })
      
      },
    }
  };
</script>

<style lang="scss">
  page {
    background-color: #ffffff; width: 100%; height: 100%;box-sizing: border-box; padding-top: 20%;
  }
  .privacy-box{position: absolute; width: 100%; left: 0; bottom: 20rpx;}
  .logo{width: 180rpx; height: 180rpx; border-radius: 50%; margin-bottom: 30rpx; overflow: hidden; box-shadow: 0 0 6px #dedede;}
  .p1{font-size: 36rpx; margin-bottom: 60rpx; font-weight: bold;}
  .login {
    padding: 0 10% ; text-align: center; width: 100%; height: 100%; display: flex; justify-content: center; box-sizing: border-box;
  }
  .btn1-box{
    background-color: #2979ff; color: #fff; border-radius: 40rpx; width: 100%; height: 80rpx; position: relative; display: flex; align-items: center; justify-content: center; font-size: 32rpx;
    .btn1{position: absolute; width: 100%; height: 100%; left: 0; top: 0; opacity: 0;}
  }
  
  .other {
    position: absolute;
    width: 100%;
    left: 0;
    bottom: 40rpx;
  }
</style>